import {
  getVipList,
  getTicketList
} from "@/static/js/vip.js";
import { requestPort } from '@/utils/request.js';
import {
  getUserInfo
} from "@/static/js/user";
let iapChannel = null;

export default {
  data() {
    return {
      userInfo: {}, //用户信息
      vipList: [], //会员列表
      showBuyVip: false, //购买会员弹窗
      normalTicketList: [], //普通问答券列表
      expertTicketList: [], //专家问答券列表
      chooseItem: {}, //打开购买会员弹窗绑定的会员信息
      openPopupType: null, //打开弹窗是会员还是问答券
      checked: true, //是否选中协议
      productIds: [], //苹果支付id
    };
  },
  onReady() { },
  onLoad(e) {
    this.platform = uni.getSystemInfoSync().platform;
    this.getVipList();
    // #ifdef APP-PLUS
    // #endif
  },
  onShow() {
    this.getUserInfo();
  },

  computed: {},
  methods: {
    //获取用户详细信息
    getUserInfo() {
      getUserInfo().then((res) => {
        this.userInfo = res.data;
      });
    },

    //获取vip列表
    async getVipList() {
      let res = await getVipList({});
      if (res.code == 1) {
        let arr = res.data;
        this.vipList = arr;
      }
      this.getNTicket();
    },

    //获取问答券
    async getNTicket() {
      let res = await getTicketList({});
      if (res.code == 1) {
        let arr = res.data;
        let arr1 = [];
        let arr2 = [];
        arr.forEach((item) => {
          if (item.type == 1) {
            arr1.push(item);
          } else if (item.type == 2) {
            arr2.push(item);
          }
        });
        this.normalTicketList = arr1;
        this.expertTicketList = arr2;
      }
    },

    //去兑换码
    toChangeCode() {
      uni.navigateTo({
        url: "./exchangeCode",
      });
    },

    //打开购买会员弹窗
    openVipPopup(e, type) {
      this.showBuyVip = true;
      this.chooseItem = e;
      this.openPopupType = type;
    },

    //关闭会员支付弹窗
    closeBuyVip() {
      this.showBuyVip = false;
      this.chooseItem = {};
    },

    //去支付
    goPayMoney(e) {
      console.log('e', e);
      let id = e.id;
      let type = this.openPopupType;
      console.log('type', type);
      // 获取是ios还是安卓
      if (this.platform == 'ios') {
        uni.showToast({
          title: '暂不支持ios支付',
          icon: 'none'
        })
        // if (type == 1) {
        //   this.payClick(e)
        // } else {
        //   this.ticketPayClick(e)
        // }
      } else {
        // if (type == 1) {
        //   uni.navigateTo({
        //     url: "/pages/my/vip/orderConfirm?id=" + id,
        //   });
        // } else {
        //   uni.navigateTo({
        //     url: "/pages/my/myHome/coupons/pay?id=" + id,
        //   });
        // }
      }
    },

    openVipXiYi() {
      uni.navigateTo({
        url: `./agreement`,
      });
    },

    checkFun(e) {
      this.checked = !this.checked;
    },
  },
};